/*---------------------------------------------------------------------------------
	Stamina

		Players can only sprint and use their flashlight for a designated time

Module.Name 	= "Stamina"
Module.Author 	= "PC Camp" <- is a moron, and didn't make this (Ben did)
Module.Website 	= "www.bbroleplay.co.uk"
---------------------------------------------------------------------------------*/

local META = FindMetaTable( "Player" )
if not META then return end

ItsTheLastThink = 0

function StartingStamina( ply )
	if not ply:GetNWBool("sleep") then
		ply.Sprint = 30
		ply.Flash = 60
	end
end
hook.Add("PlayerSpawn","StartingStamina",StartingStamina)



function META:GetSprint()
	return math.Clamp( self.Sprint, 0, 30 )
end

function META:SetSprint(spt)
	self.Sprint = spt
end

function Stankeypress( ply, key )
	if key == IN_SPEED and ply:GetSprint() < 3 then
		ply:ConCommand( "-speed\n" )
	end
end
hook.Add("KeyPress","staminakeypress",Stankeypress)

function ThinkOfDisShiz()
	local now = CurTime()
	local delta = now - ItsTheLastThink
	for k, ply in pairs( player.GetAll() ) do
		
			
		if ply:KeyDown( IN_SPEED ) and ply:Alive() and ply:GetVelocity():Length() > 10 and not ply:GetNWBool("sleep") then
			local eng = math.Clamp( ply:GetSprint()  - (delta / 2) , 0, 30 )

			ply:SetSprint( eng )

			if eng <= 0 then
				ply:ConCommand( "-speed\n" )
			end
		else
			local setdis = math.Clamp( ply:GetSprint() + delta, 0, 30 )
			ply:SetSprint( setdis )
		end
		
		if ply.Sprint != 30 then
			umsg.Start("GetStamina", ply)
				umsg.Float( ply:GetSprint() )
			umsg.End()
		
		end
		

		
	end
	ItsTheLastThink = now
end
hook.Add("Think","ThinkOfDisShiz",ThinkOfDisShiz)

